(function(){
	function getData(obj){
		try{
			var f = new Function("return ("+obj.value+");")();
			obj.className = "";
			return window.parseFloat(f);
		}catch(err){
			obj.className = "error";
			obj.value = "无效数据";
			goFlag = false;
			return null;
		}
	}
	Number.prototype.format = function(format){
		var temp = Math.pow(10,format);
		return window.parseInt(this * temp, 10) / temp;
	};
	function $(s){
		return document.getElementById(s);
	}
	var goFlag = true;
	function go(){
		goFlag = true;
		var me_mianban = getData($("me_mianban"));
		var me_jinshen = getData($("me_jinshen"));
		var me_yuancheng = getData($("me_yuancheng"));
		var me_neigong = getData($("me_neigong"));
		var me_binru = getData($("me_binru"));
		
		var me_jn_count = getData($("me_jn_count"));
		var me_jm_bs_u = getData($("me_jm_bs_u"));
		var me_ng_bs_u = getData($("me_ng_bs_u"));
		
		var me_ng_u = getData($("me_ng_u"));
		var me_zb_u = getData($("me_zb_u"));
		var me_pz_u = getData($("me_pz_u"));
		var me_jn_u = getData($("me_jn_u"));
		
		var me_bw_bs_u = getData($("me_bw_bs_u"));
		var me_bw_sh_u = getData($("me_bw_sh_u"));
		
		var dr_wai = getData($("dr_wai"));
		var dr_ng = getData($("dr_ng"));
		
		if(!goFlag){
			alert("存在无效数据");
			$("jg_state").reset();
			return;
		}
		
		var jy_wgfy = (dr_wai * 0.0001) / (1 + (dr_wai * 0.0001));
		var jy_ngfy = (dr_ng * 0.001) / (1 + (dr_ng * 0.001));
		$("jg_dr_wai").value = (jy_wgfy*100).format(4);
		$("jg_dr_ng").value = (jy_ngfy*100).format(4);
		
		var d_binru_per = me_binru / me_jn_count;
		var d_jiben_all = me_mianban + me_jinshen + me_yuancheng + me_neigong;
		var d_jiben_per = d_jiben_all / me_jn_count;
		
		var jc_bs = 2 + me_jm_bs_u + me_ng_bs_u + me_bw_bs_u;
		
		var jc_bw_per = me_bw_sh_u * (1 + me_ng_u);
		var jc_jiben_per = d_jiben_per * (1 + me_ng_u) * (1 + me_zb_u + me_pz_u) * (1 + me_jn_u);
		
		var d_damage_per_jc = jc_jiben_per + jc_bw_per + d_binru_per;
		var d_damage_all_jc = d_damage_per_jc * me_jn_count;
		var d_damage_per_jc_bj = (jc_jiben_per + jc_bw_per) * jc_bs + d_binru_per;
		var d_damage_all_jc_bj = d_damage_per_jc_bj * me_jn_count;
		
		$("jg_sh_per").value = d_damage_per_jc.toFixed(2);
		$("jg_sh_bj_per").value = d_damage_per_jc_bj.toFixed(2);
		$("jg_sh_all").value = d_damage_all_jc.toFixed(2);
		$("jg_sh_bj_all").value = d_damage_all_jc_bj.toFixed(2);
		
		$("jg_wg_sh_per").value = (d_damage_per_jc * (1 - jy_wgfy)).toFixed(2);
		$("jg_wg_sh_bj_per").value = (d_damage_per_jc_bj * (1 - jy_wgfy)).toFixed(2);
		$("jg_wg_sh_all").value = ((d_damage_per_jc * me_jn_count) * (1 - jy_wgfy)).toFixed(2);
		$("jg_wg_sh_bj_all").value = ((d_damage_per_jc_bj * me_jn_count) * (1 - jy_wgfy)).toFixed(2);
		
		$("jg_ng_sh_per").value = (d_damage_per_jc * (1 - jy_ngfy)).toFixed(2);
		$("jg_ng_sh_bj_per").value = (d_damage_per_jc_bj * (1 - jy_ngfy)).toFixed(2);
		$("jg_ng_sh_all").value = ((d_damage_per_jc * me_jn_count) * (1 - jy_ngfy)).toFixed(2);
		$("jg_ng_sh_bj_all").value = ((d_damage_per_jc_bj * me_jn_count) * (1 - jy_ngfy)).toFixed(2);
	}
	$("me_mianban").onkeypress =
	$("me_jinshen").onkeypress = 
	$("me_yuancheng").onkeypress =
	$("me_neigong").onkeypress = 
	$("me_binru").onkeypress = 

	$("me_jn_count").onkeypress =
	$("me_jm_bs_u").onkeypress = 
	$("me_ng_bs_u").onkeypress = 

	$("me_ng_u").onkeypress = 
	$("me_zb_u").onkeypress =
	$("me_pz_u").onkeypress = 
	$("me_jn_u").onkeypress = 

	$("me_bw_bs_u").onkeypress = 
	$("me_bw_sh_u").onkeypress = 

	$("dr_wai").onkeypress = 
	$("dr_ng").onkeypress = 
	function(e){
		e = e || window.event;
		if(e.keyCode == 13) go();
	};
	$("me_start").onclick = 
	$("dr_start").onclick = 
	function(e){
		go();
	};
})();